/*
 * Copyright 2010 Kevin L'Huillier <klhuillier@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lhuillier.pwsafe.io.codec;


import org.lhuillier.pwsafe.model.RawField;
import org.lhuillier.pwsafe.model.Record;


/**
 * Converts between a {@link RawField} record value in a {@link RawDb} and a 
 * specific property in a {@link Record}.
 * <p>
 * Because a converter for a custom record type would rely on a type other than
 * Record, and not necessarily a subclass of Record, this only supports
 * the known Record type. 
 */
public interface FieldConverter {
    /**
     * @return the type ID that is handled by this instance.
     */
    byte handledTypeId();
    
    /**
     * Converts a raw value to the appropriate type for the field and assigns
     * it to the provided Record.
     */
    void toRecord(RawField raw, Record record);
    
    /**
     * Converts a specific field from the Record to a RawField which is
     * added to the RawRecord's fields.
     */
    void toRaw(Record record, RawRecord raw);
}
